Using OLR
vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
p <- plot(vclust)
par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
brick <- count(train.data$brick) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "brick")
wood <- count(train.data$wood) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wood")
mixed <- count(train.data$mixed) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "mixed")
TC_mature_soil <- count(train.data$TC_mature_soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_mature_soil")
T_construction <- count(train.data$T_construction ) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "T_construction ")
spring <- count(train.data$spring) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "spring")
landfill <- count(train.data$landfill) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "landfill")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
conc_rainfall <- count(train.data$conc_rainfall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_saprolite_soil <- count(train.data$TC_saprolite_soil ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_saprolite_soil ")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
TC_unstable_structure <- count(train.data$TC_unstable_structure ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_unstable_structure ")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
TC_weath_rock <- count(train.data$TC_weath_rock ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_weath_rock ")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil, banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)
df
## x freq Percentage Classifier
## 1 FALSE 31 11.698113 brick
## 2 TRUE 499 188.301887 brick
## 3 FALSE 452 170.566038 wood
## 4 TRUE 78 29.433962 wood
## 5 FALSE 493 186.037736 mixed
## 6 TRUE 37 13.962264 mixed
## 7 FALSE 246 92.830189 TC_mature_soil
## 8 TRUE 284 107.169811 TC_mature_soil
## 9 FALSE 213 80.377358 T_construction
## 10 TRUE 317 119.622642 T_construction
## 11 FALSE 513 193.584906 spring
## 12 TRUE 17 6.415094 spring
## 13 FALSE 331 124.905660 landfill
## 14 TRUE 199 75.094340 landfill
## 15 FALSE 345 130.188679 garbage
## 16 TRUE 185 69.811321 garbage
## 17 FALSE 436 164.528302 crack
## 18 TRUE 94 35.471698 crack
## 19 FALSE 498 187.924528 leaning_wall
## 20 TRUE 32 12.075472 leaning_wall
## 21 FALSE 328 123.773585 DepTaludeAterro
## 22 TRUE 202 76.226415 DepTaludeAterro
## 23 FALSE 467 176.226415 scars
## 24 TRUE 63 23.773585 scars
## 25 FALSE 437 164.905660 tilted
## 26 TRUE 93 35.094340 tilted
## 27 FALSE 12 4.528302 conc_rainfall
## 28 TRUE 518 195.471698 conc_rainfall
## 29 FALSE 204 76.981132 wastewater
## 30 TRUE 326 123.018868 wastewater
## 31 FALSE 344 129.811321 conc_rainfall_water
## 32 TRUE 186 70.188679 conc_rainfall_water
## 33 FALSE 525 198.113208 septic_tank
## 34 TRUE 5 1.886792 septic_tank
## 35 C 32 30.188679 angle
## 36 D 119 112.264151 angle
## 37 E 379 357.547170 angle
## 38 FALSE 347 130.943396 EN
## 39 TRUE 183 69.056604 EN
## 40 FALSE 24 9.056604 TC
## 41 TRUE 506 190.943396 TC
## 42 FALSE 441 166.415094 TC_saprolite_soil
## 43 TRUE 89 33.584906 TC_saprolite_soil
## 44 FALSE 349 131.698113 banana
## 45 TRUE 181 68.301887 banana
## 46 Y 64 36.219581 drainage
## 47 P 236 133.559706 drainage
## 48 N 230 130.164120 drainage
## 49 FALSE 496 187.169811 deforestation
## 50 TRUE 34 12.830189 deforestation
## 51 FALSE 519 195.849057 TC_unstable_structure
## 52 TRUE 11 4.150943 TC_unstable_structure
## 53 FALSE 207 78.113208 tree
## 54 TRUE 323 121.886792 tree
## 55 FALSE 156 58.867925 ground_veg
## 56 TRUE 374 141.132075 ground_veg
## 57 d1 69 52.075472 density
## 58 d2 425 320.754717 density
## 59 d3 36 27.169811 density
## 60 FALSE 518 195.471698 TC_weath_rock
## 61 TRUE 12 4.528302 TC_weath_rock
## 62 FALSE 528 199.245283 fracture
## 63 TRUE 2 0.754717 fracture
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk ~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.6018733932 0.4872512 -1.23524245 1.083701e-01
## woodTRUE 1.0656776588 0.3362246 3.16954139 7.633986e-04
## ENTRUE 1.0997471170 0.3694436 2.97676612 1.456531e-03
## TC_mature_soilTRUE 0.4815750531 0.2276160 2.11573455 1.718370e-02
## T_constructionTRUE 0.3318448911 0.3648991 0.90941556 1.815654e-01
## springTRUE -0.8185097624 0.6849166 -1.19505030 1.160337e-01
## landfillTRUE 0.1533903325 0.3289735 0.46626950 3.205113e-01
## leakTRUE 0.0004770532 0.2417038 0.00197371 4.992126e-01
## garbageTRUE 0.0710703108 0.2982016 0.23832974 4.058127e-01
## crackTRUE 1.9256460052 0.3445374 5.58907742 1.141396e-08
## leaning_wallTRUE 1.9860854014 0.5445733 3.64704850 1.326349e-04
## scarsTRUE 4.1183626917 0.3999813 10.29638909 3.657799e-25
## downward_floorTRUE 1.1296938425 0.3851397 2.93320528 1.677410e-03
## tiltedTRUE 1.1970379105 0.3447847 3.47184178 2.584504e-04
## septic_tankTRUE 1.3602767553 1.0310445 1.31931919 9.353121e-02
## conc_rainfallTRUE 2.4958976948 0.7630364 3.27100745 5.358254e-04
## wastewaterTRUE 0.9940218278 0.2471774 4.02149156 2.891539e-05
## ground_vegTRUE 1.1069885289 0.2683566 4.12506473 1.853153e-05
## angleD 0.8548078524 0.4882809 1.75064785 4.000329e-02
## angleE 1.2593718860 0.5493167 2.29261535 1.093508e-02
## TC_saprolite_soilTRUE -0.0124332038 0.2920369 -0.04257408 4.830205e-01
## R1|R2 2.7652996508 1.0594631 2.61009521 4.525851e-03
## R2|R3 7.1722928548 1.1162619 6.42527758 6.581455e-11
## R3|R4 12.8357693844 1.2659224 10.13945949 1.845682e-24
stargazer((ctable), type="text", style="default", digits = 2)
##
## =======================================================
## Value Std. Error t value p value
## -------------------------------------------------------
## brickTRUE -0.60 0.49 -1.24 0.11
## woodTRUE 1.07 0.34 3.17 0.001
## ENTRUE 1.10 0.37 2.98 0.001
## TC_mature_soilTRUE 0.48 0.23 2.12 0.02
## T_constructionTRUE 0.33 0.36 0.91 0.18
## springTRUE -0.82 0.68 -1.20 0.12
## landfillTRUE 0.15 0.33 0.47 0.32
## leakTRUE 0.0005 0.24 0.002 0.50
## garbageTRUE 0.07 0.30 0.24 0.41
## crackTRUE 1.93 0.34 5.59 0
## leaning_wallTRUE 1.99 0.54 3.65 0.0001
## scarsTRUE 4.12 0.40 10.30 0
## downward_floorTRUE 1.13 0.39 2.93 0.002
## tiltedTRUE 1.20 0.34 3.47 0.0003
## septic_tankTRUE 1.36 1.03 1.32 0.09
## conc_rainfallTRUE 2.50 0.76 3.27 0.001
## wastewaterTRUE 0.99 0.25 4.02 0.0000
## ground_vegTRUE 1.11 0.27 4.13 0.0000
## angleD 0.85 0.49 1.75 0.04
## angleE 1.26 0.55 2.29 0.01
## TC_saprolite_soilTRUE -0.01 0.29 -0.04 0.48
## R1| R2 2.77 1.06 2.61 0.005
## R2| R3 7.17 1.12 6.43 0
## R3| R4 12.84 1.27 10.14 0
## -------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+---------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+---------+------------+----------+
## |brick |No | 31|Inf | 3.401197| 1.232143681|-0.8938179|
## | |Yes|498|Inf | 2.285041|-0.072320662|-2.0069620|
## +-----------------+---+---+----+---------+------------+----------+
## |wood |No |451|Inf | 2.199691|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.637586| 0.998528830|-0.6359888|
## +-----------------+---+---+----+---------+------------+----------+
## |EN |No |346|Inf | 1.850296|-0.483174092|-2.4693542|
## | |Yes|183|Inf | Inf| 0.950976290|-1.2422550|
## +-----------------+---+---+----+---------+------------+----------+
## |TC_mature_soil |No |246|Inf | 1.864785|-0.328115642|-2.0522906|
## | |Yes|283|Inf | 2.955654| 0.277383320|-1.8041820|
## +-----------------+---+---+----+---------+------------+----------+
## |T_construction |No |213|Inf | 1.559566|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.421000| 0.572069249|-1.4715386|
## +-----------------+---+---+----+---------+------------+----------+
## |spring |No |512|Inf | 2.291890|-0.031252544|-2.0005935|
## | |Yes| 17|Inf | Inf| 0.875468737|-0.3566749|
## +-----------------+---+---+----+---------+------------+----------+
## |landfill |No |330|Inf | 1.820333|-0.520534438|-2.6888188|
## | |Yes|199|Inf | 5.288267| 0.888316880|-1.1737329|
## +-----------------+---+---+----+---------+------------+----------+
## |leak |No |343|Inf | 1.942582|-0.335472736|-2.4203681|
## | |Yes|186|Inf | 3.817712| 0.621403276|-1.2947272|
## +-----------------+---+---+----+---------+------------+----------+
## |garbage |No |345|Inf | 2.089262|-0.250578322|-2.3154058|
## | |Yes|184|Inf | 2.967561| 0.464707942|-1.3795147|
## +-----------------+---+---+----+---------+------------+----------+
## |crack |No |435|Inf | 2.134938|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.532599| 2.685577345|-0.1706255|
## +-----------------+---+---+----+---------+------------+----------+
## |leaning_wall |No |497|Inf | 2.259100|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +-----------------+---+---+----+---------+------------+----------+
## |scars |No |327|Inf | 1.784642|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +-----------------+---+---+----+---------+------------+----------+
## |downward_floor |No |466|Inf | 2.187723|-0.267681406|-2.3120638|
## | |Yes| 63|Inf | Inf| 4.127134385|-0.3528214|
## +-----------------+---+---+----+---------+------------+----------+
## |tilted |No |436|Inf | 2.113432|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +-----------------+---+---+----+---------+------------+----------+
## |septic_tank |No |524|Inf | 2.317369|-0.015267472|-1.9372144|
## | |Yes| 5|Inf | Inf| 1.386294361|-0.4054651|
## +-----------------+---+---+----+---------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.098612|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.534114| 0.034819765|-1.8875152|
## +-----------------+---+---+----+---------+------------+----------+
## |wastewater |No |204|Inf | 1.574551|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.261297| 0.253659095|-1.5059589|
## +-----------------+---+---+----+---------+------------+----------+
## |ground_veg |No |156|Inf | 1.203973|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.493749| 0.543850879|-1.6518586|
## +-----------------+---+---+----+---------+------------+----------+
## |angle |C | 32|Inf | Inf|-0.251314428|-3.4339872|
## | |D |119|Inf | 4.770685| 1.000172216|-1.2259517|
## | |E |378|Inf | 1.976494|-0.276887827|-2.1341664|
## +-----------------+---+---+----+---------+------------+----------+
## |TC_saprolite_soil|No |440|Inf | 2.222736|-0.063657852|-1.9881328|
## | |Yes| 89|Inf | 3.056357| 0.294239473|-1.5960149|
## +-----------------+---+---+----+---------+------------+----------+
## |Overall | |529|Inf | 2.327797|-0.003780723|-1.9138903|
## +-----------------+---+---+----+---------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.35495918 0.5336091 -0.66520447 2.529599e-01
## woodTRUE 0.86438238 0.3532877 2.44668142 7.208911e-03
## ENTRUE 0.94074660 0.3901683 2.41113042 7.951580e-03
## TC_mature_soilTRUE 0.41739746 0.2408280 1.73317649 4.153215e-02
## T_constructionTRUE 0.45321136 0.3763691 1.20416722 1.142625e-01
## landfillTRUE 0.10904467 0.3342528 0.32623417 3.721236e-01
## leakTRUE -0.15857083 0.2479088 -0.63963367 2.612054e-01
## garbageTRUE 0.07052007 0.3062060 0.23030273 4.089283e-01
## crackTRUE 1.89848152 0.3466747 5.47626270 2.172013e-08
## leaning_wallTRUE 1.99189222 0.5551940 3.58774095 1.667777e-04
## treeTRUE -0.10217337 0.2478906 -0.41217125 3.401070e-01
## downward_floorTRUE 1.02613575 0.3812123 2.69177014 3.553696e-03
## tiltedTRUE 0.95345086 0.3415403 2.79162019 2.622244e-03
## ground_vegTRUE 1.00521050 0.2886202 3.48281417 2.480863e-04
## scarsTRUE 4.05569868 0.4022152 10.08340445 3.270967e-24
## mixedTRUE 0.29482505 0.5088802 0.57936043 2.811730e-01
## conc_rainfallTRUE 1.96259700 0.7813614 2.51176591 6.006437e-03
## wastewaterTRUE 0.81439888 0.2539654 3.20673147 6.712612e-04
## angleD 0.70185027 0.5033650 1.39431690 8.161096e-02
## angleE 1.13347791 0.5605856 2.02195340 2.159058e-02
## bananaTRUE 0.17111166 0.2630963 0.65037665 2.577245e-01
## drainage.L 1.13495754 0.2900471 3.91301076 4.557624e-05
## drainage.Q 0.04428922 0.1931407 0.22931062 4.093138e-01
## TC_saprolite_soilTRUE -0.01056727 0.3000107 -0.03522297 4.859510e-01
## TCTRUE -0.41159268 0.5848452 -0.70376345 2.407900e-01
## deforestationTRUE 0.43622231 0.4313084 1.01139296 1.559142e-01
## R1|R2 1.69307012 1.3186446 1.28394726 9.958021e-02
## R2|R3 6.35997085 1.3494722 4.71293218 1.220887e-06
## R3|R4 12.00955718 1.4790896 8.11956041 2.339376e-16
stargazer((ctable), type="text", style="default", digits=2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.35 0.53 -0.67 0.25
## woodTRUE 0.86 0.35 2.45 0.01
## ENTRUE 0.94 0.39 2.41 0.01
## TC_mature_soilTRUE 0.42 0.24 1.73 0.04
## T_constructionTRUE 0.45 0.38 1.20 0.11
## landfillTRUE 0.11 0.33 0.33 0.37
## leakTRUE -0.16 0.25 -0.64 0.26
## garbageTRUE 0.07 0.31 0.23 0.41
## crackTRUE 1.90 0.35 5.48 0.0000
## leaning_wallTRUE 1.99 0.56 3.59 0.0002
## treeTRUE -0.10 0.25 -0.41 0.34
## downward_floorTRUE 1.03 0.38 2.69 0.004
## tiltedTRUE 0.95 0.34 2.79 0.003
## ground_vegTRUE 1.01 0.29 3.48 0.0002
## scarsTRUE 4.06 0.40 10.08 0
## mixedTRUE 0.29 0.51 0.58 0.28
## conc_rainfallTRUE 1.96 0.78 2.51 0.01
## wastewaterTRUE 0.81 0.25 3.21 0.001
## angleD 0.70 0.50 1.39 0.08
## angleE 1.13 0.56 2.02 0.02
## bananaTRUE 0.17 0.26 0.65 0.26
## drainage.L 1.13 0.29 3.91 0.0000
## drainage.Q 0.04 0.19 0.23 0.41
## TC_saprolite_soilTRUE -0.01 0.30 -0.04 0.49
## TCTRUE -0.41 0.58 -0.70 0.24
## deforestationTRUE 0.44 0.43 1.01 0.16
## R1| R2 1.69 1.32 1.28 0.10
## R2| R3 6.36 1.35 4.71 0.0000
## R3| R4 12.01 1.48 8.12 0
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 31|Inf | 3.4011974| 1.232143681|-0.8938179|
## | |Yes|498|Inf | 2.2850408|-0.072320662|-2.0069620|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |451|Inf | 2.1996907|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.6375862| 0.998528830|-0.6359888|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |346|Inf | 1.8502960|-0.483174092|-2.4693542|
## | |Yes|183|Inf | Inf| 0.950976290|-1.2422550|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |246|Inf | 1.8647846|-0.328115642|-2.0522906|
## | |Yes|283|Inf | 2.9556540| 0.277383320|-1.8041820|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |213|Inf | 1.5595661|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.4210000| 0.572069249|-1.4715386|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |330|Inf | 1.8203328|-0.520534438|-2.6888188|
## | |Yes|199|Inf | 5.2882670| 0.888316880|-1.1737329|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |343|Inf | 1.9425824|-0.335472736|-2.4203681|
## | |Yes|186|Inf | 3.8177123| 0.621403276|-1.2947272|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |345|Inf | 2.0892616|-0.250578322|-2.3154058|
## | |Yes|184|Inf | 2.9675614| 0.464707942|-1.3795147|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |435|Inf | 2.1349379|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.5325995| 2.685577345|-0.1706255|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +-----------------+---+---+----+----------+------------+----------+
## |tree |No |206|Inf | 1.6933194|-0.536801110|-2.1758334|
## | |Yes|323|Inf | 3.0220496| 0.331167184|-1.7702533|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |466|Inf | 2.1877233|-0.267681406|-2.3120638|
## | |Yes| 63|Inf | Inf| 4.127134385|-0.3528214|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1134317|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |156|Inf | 1.2039728|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.4937489| 0.543850879|-1.6518586|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |327|Inf | 1.7846420|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed |No |492|Inf | 2.2716776|-0.089490571|-2.0126015|
## | |Yes| 37|Inf | 3.5835189| 1.287854288|-0.9932518|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.0986123|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.5341144| 0.034819765|-1.8875152|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.5745507|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.2612965| 0.253659095|-1.5059589|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 32|Inf | Inf|-0.251314428|-3.4339872|
## | |D |119|Inf | 4.7706846| 1.000172216|-1.2259517|
## | |E |378|Inf | 1.9764936|-0.276887827|-2.1341664|
## +-----------------+---+---+----+----------+------------+----------+
## |banana |No |348|Inf | 1.9328381|-0.383958903|-2.1908551|
## | |Yes|181|Inf | 4.0831713| 0.751741345|-1.5007047|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage |Y | 64|Inf | 0.6466272|-1.686398954| -Inf|
## | |P |235|Inf | 2.3214536|-0.680408155|-2.7591054|
## | |N |230|Inf | 4.0342406| 1.157452789|-1.1814999|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |440|Inf | 2.2227362|-0.063657852|-1.9881328|
## | |Yes| 89|Inf | 3.0563569| 0.294239473|-1.5960149|
## +-----------------+---+---+----+----------+------------+----------+
## |TC |No | 24|Inf | Inf| 1.098612289|-1.0986123|
## | |Yes|505|Inf | 2.2767216|-0.051496526|-1.9664354|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation |No |495|Inf | 2.3025851| 0.028284714|-1.8893979|
## | |Yes| 34|Inf | 2.7725887|-0.479573080|-2.3353749|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## woodTRUE 0.83135836 0.3311830 2.5102692 6.031958e-03
## TC_mature_soilTRUE 0.39939524 0.2277066 1.7539909 3.971603e-02
## T_constructionTRUE 0.42433259 0.2963313 1.4319532 7.607861e-02
## landfillTRUE 0.21270739 0.3001804 0.7085985 2.392868e-01
## crackTRUE 1.87359757 0.3341107 5.6077144 1.025080e-08
## leaning_wallTRUE 2.00789592 0.5515410 3.6405200 1.360440e-04
## treeTRUE -0.06931478 0.2384102 -0.2907375 3.856260e-01
## downward_floorTRUE 0.96970117 0.3708572 2.6147565 4.464554e-03
## tiltedTRUE 1.02795041 0.3347492 3.0708075 1.067404e-03
## ground_vegTRUE 0.96912298 0.2813959 3.4439838 2.866051e-04
## scarsTRUE 4.04620548 0.3973464 10.1830690 1.179993e-24
## conc_rainfallTRUE 1.89437723 0.7549782 2.5091814 6.050566e-03
## wastewaterTRUE 0.81017630 0.2456282 3.2983849 4.862137e-04
## bananaTRUE 0.25335547 0.2482114 1.0207247 1.536925e-01
## drainage.L 1.18629284 0.2848233 4.1650128 1.556676e-05
## drainage.Q 0.03989566 0.1907864 0.2091116 4.171805e-01
## R1|R2 1.20693488 0.7431927 1.6239865 5.218934e-02
## R2|R3 5.76089623 0.7931696 7.2631326 1.891134e-13
## R3|R4 11.31771066 0.9556319 11.8431696 1.167300e-32
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 0.83 0.33 2.51 0.01
## TC_mature_soilTRUE 0.40 0.23 1.75 0.04
## T_constructionTRUE 0.42 0.30 1.43 0.08
## landfillTRUE 0.21 0.30 0.71 0.24
## crackTRUE 1.87 0.33 5.61 0
## leaning_wallTRUE 2.01 0.55 3.64 0.0001
## treeTRUE -0.07 0.24 -0.29 0.39
## downward_floorTRUE 0.97 0.37 2.61 0.004
## tiltedTRUE 1.03 0.33 3.07 0.001
## ground_vegTRUE 0.97 0.28 3.44 0.0003
## scarsTRUE 4.05 0.40 10.18 0
## conc_rainfallTRUE 1.89 0.75 2.51 0.01
## wastewaterTRUE 0.81 0.25 3.30 0.0005
## bananaTRUE 0.25 0.25 1.02 0.15
## drainage.L 1.19 0.28 4.17 0.0000
## drainage.Q 0.04 0.19 0.21 0.42
## R1| R2 1.21 0.74 1.62 0.05
## R2| R3 5.76 0.79 7.26 0
## R3| R4 11.32 0.96 11.84 0
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |451|Inf | 2.1996907|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.6375862| 0.998528830|-0.6359888|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |246|Inf | 1.8647846|-0.328115642|-2.0522906|
## | |Yes|283|Inf | 2.9556540| 0.277383320|-1.8041820|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.5595661|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.4210000| 0.572069249|-1.4715386|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |330|Inf | 1.8203328|-0.520534438|-2.6888188|
## | |Yes|199|Inf | 5.2882670| 0.888316880|-1.1737329|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |435|Inf | 2.1349379|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.5325995| 2.685577345|-0.1706255|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |206|Inf | 1.6933194|-0.536801110|-2.1758334|
## | |Yes|323|Inf | 3.0220496| 0.331167184|-1.7702533|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |466|Inf | 2.1877233|-0.267681406|-2.3120638|
## | |Yes| 63|Inf | Inf| 4.127134385|-0.3528214|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1134317|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |156|Inf | 1.2039728|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.4937489| 0.543850879|-1.6518586|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |327|Inf | 1.7846420|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.0986123|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.5341144| 0.034819765|-1.8875152|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.5745507|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.2612965| 0.253659095|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |348|Inf | 1.9328381|-0.383958903|-2.1908551|
## | |Yes|181|Inf | 4.0831713| 0.751741345|-1.5007047|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 64|Inf | 0.6466272|-1.686398954| -Inf|
## | |P |235|Inf | 2.3214536|-0.680408155|-2.7591054|
## | |N |230|Inf | 4.0342406| 1.157452789|-1.1814999|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## woodTRUE 0.83393744 0.3306662 2.5219917 6.031958e-03
## TC_mature_soilTRUE 0.37613377 0.2251925 1.6702768 3.971603e-02
## T_constructionTRUE 0.55082418 0.2365747 2.3283307 7.607861e-02
## crackTRUE 1.89755683 0.3325553 5.7059887 2.392868e-01
## leaning_wallTRUE 1.99722089 0.5533274 3.6094740 1.025080e-08
## treeTRUE -0.08071835 0.2378132 -0.3394191 1.360440e-04
## downward_floorTRUE 0.99528575 0.3691033 2.6964964 3.856260e-01
## tiltedTRUE 1.06270681 0.3308423 3.2121246 4.464554e-03
## ground_vegTRUE 0.98013776 0.2806946 3.4918301 1.067404e-03
## scarsTRUE 4.04228874 0.3974688 10.1700786 2.866051e-04
## conc_rainfallTRUE 1.92878772 0.7560841 2.5510228 1.179993e-24
## wastewaterTRUE 0.78152454 0.2423022 3.2254122 6.050566e-03
## bananaTRUE 0.25426072 0.2481501 1.0246247 4.862137e-04
## drainage.L 1.19379934 0.2845278 4.1957217 1.536925e-01
## drainage.Q 0.04469379 0.1906217 0.2344632 1.556676e-05
## R1|R2 1.22366684 0.7454736 1.6414624 4.171805e-01
## R2|R3 5.77527951 0.7954518 7.2603764 5.218934e-02
## R3|R4 11.32476847 0.9576886 11.8251052 1.891134e-13
stargazer((ctable), type="text", style="default", digits=2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 0.83 0.33 2.52 0.01
## TC_mature_soilTRUE 0.38 0.23 1.67 0.04
## T_constructionTRUE 0.55 0.24 2.33 0.08
## crackTRUE 1.90 0.33 5.71 0.24
## leaning_wallTRUE 2.00 0.55 3.61 0
## treeTRUE -0.08 0.24 -0.34 0.0001
## downward_floorTRUE 1.00 0.37 2.70 0.39
## tiltedTRUE 1.06 0.33 3.21 0.004
## ground_vegTRUE 0.98 0.28 3.49 0.001
## scarsTRUE 4.04 0.40 10.17 0.0003
## conc_rainfallTRUE 1.93 0.76 2.55 0
## wastewaterTRUE 0.78 0.24 3.23 0.01
## bananaTRUE 0.25 0.25 1.02 0.0005
## drainage.L 1.19 0.28 4.20 0.15
## drainage.Q 0.04 0.19 0.23 0.0000
## R1| R2 1.22 0.75 1.64 0.42
## R2| R3 5.78 0.80 7.26 0.05
## R3| R4 11.32 0.96 11.83 0
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |451|Inf | 2.1996907|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.6375862| 0.998528830|-0.6359888|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |246|Inf | 1.8647846|-0.328115642|-2.0522906|
## | |Yes|283|Inf | 2.9556540| 0.277383320|-1.8041820|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.5595661|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.4210000| 0.572069249|-1.4715386|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |435|Inf | 2.1349379|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.5325995| 2.685577345|-0.1706255|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |206|Inf | 1.6933194|-0.536801110|-2.1758334|
## | |Yes|323|Inf | 3.0220496| 0.331167184|-1.7702533|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |466|Inf | 2.1877233|-0.267681406|-2.3120638|
## | |Yes| 63|Inf | Inf| 4.127134385|-0.3528214|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1134317|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |156|Inf | 1.2039728|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.4937489| 0.543850879|-1.6518586|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |327|Inf | 1.7846420|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.0986123|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.5341144| 0.034819765|-1.8875152|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |204|Inf | 1.5745507|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.2612965| 0.253659095|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |348|Inf | 1.9328381|-0.383958903|-2.1908551|
## | |Yes|181|Inf | 4.0831713| 0.751741345|-1.5007047|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 64|Inf | 0.6466272|-1.686398954| -Inf|
## | |P |235|Inf | 2.3214536|-0.680408155|-2.7591054|
## | |N |230|Inf | 4.0342406| 1.157452789|-1.1814999|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.4295501 0.4683847 -0.9170881 1.795482e-01
## woodTRUE 1.0378407 0.3266174 3.1775424 7.426449e-04
## TC_mature_soilTRUE 0.4538598 0.2198583 2.0643289 1.949327e-02
## T_constructionTRUE 0.4965043 0.2302329 2.1565311 1.552111e-02
## crackTRUE 1.8479539 0.3270532 5.6503163 8.007644e-09
## leaning_wallTRUE 1.8869560 0.5371937 3.5126175 2.218579e-04
## scarsTRUE 4.1572032 0.3971522 10.4675318 6.088841e-26
## downward_floorTRUE 1.1749503 0.3708120 3.1685878 7.659074e-04
## tiltedTRUE 1.2501260 0.3302682 3.7851844 7.679733e-05
## conc_rainfallTRUE 2.4228941 0.7349069 3.2968722 4.888398e-04
## wastewaterTRUE 0.9727841 0.2344552 4.1491252 1.668741e-05
## ground_vegTRUE 1.1690630 0.2553513 4.5782540 2.344366e-06
## R1|R2 1.5810660 0.8618157 1.8345757 3.328429e-02
## R2|R3 5.8742572 0.9142081 6.4255143 6.571219e-11
## R3|R4 11.3625068 1.0531004 10.7895760 1.927822e-27
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.43 0.47 -0.92 0.18
## woodTRUE 1.04 0.33 3.18 0.001
## TC_mature_soilTRUE 0.45 0.22 2.06 0.02
## T_constructionTRUE 0.50 0.23 2.16 0.02
## crackTRUE 1.85 0.33 5.65 0
## leaning_wallTRUE 1.89 0.54 3.51 0.0002
## scarsTRUE 4.16 0.40 10.47 0
## downward_floorTRUE 1.17 0.37 3.17 0.001
## tiltedTRUE 1.25 0.33 3.79 0.0001
## conc_rainfallTRUE 2.42 0.73 3.30 0.0005
## wastewaterTRUE 0.97 0.23 4.15 0.0000
## ground_vegTRUE 1.17 0.26 4.58 0.0000
## R1| R2 1.58 0.86 1.83 0.03
## R2| R3 5.87 0.91 6.43 0
## R3| R4 11.36 1.05 10.79 0
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+---------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+---------+------------+----------+
## |brick |No | 31|Inf | 3.401197| 1.232143681|-0.8938179|
## | |Yes|498|Inf | 2.285041|-0.072320662|-2.0069620|
## +--------------+---+---+----+---------+------------+----------+
## |wood |No |451|Inf | 2.199691|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.637586| 0.998528830|-0.6359888|
## +--------------+---+---+----+---------+------------+----------+
## |TC_mature_soil|No |246|Inf | 1.864785|-0.328115642|-2.0522906|
## | |Yes|283|Inf | 2.955654| 0.277383320|-1.8041820|
## +--------------+---+---+----+---------+------------+----------+
## |T_construction|No |213|Inf | 1.559566|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.421000| 0.572069249|-1.4715386|
## +--------------+---+---+----+---------+------------+----------+
## |crack |No |435|Inf | 2.134938|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.532599| 2.685577345|-0.1706255|
## +--------------+---+---+----+---------+------------+----------+
## |leaning_wall |No |497|Inf | 2.259100|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +--------------+---+---+----+---------+------------+----------+
## |scars |No |327|Inf | 1.784642|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +--------------+---+---+----+---------+------------+----------+
## |downward_floor|No |466|Inf | 2.187723|-0.267681406|-2.3120638|
## | |Yes| 63|Inf | Inf| 4.127134385|-0.3528214|
## +--------------+---+---+----+---------+------------+----------+
## |tilted |No |436|Inf | 2.113432|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +--------------+---+---+----+---------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.098612|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.534114| 0.034819765|-1.8875152|
## +--------------+---+---+----+---------+------------+----------+
## |wastewater |No |204|Inf | 1.574551|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.261297| 0.253659095|-1.5059589|
## +--------------+---+---+----+---------+------------+----------+
## |ground_veg |No |156|Inf | 1.203973|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.493749| 0.543850879|-1.6518586|
## +--------------+---+---+----+---------+------------+----------+
## |Overall | |529|Inf | 2.327797|-0.003780723|-1.9138903|
## +--------------+---+---+----+---------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.53202164 0.5208014 -1.0215441 1.534984e-01
## woodTRUE 0.95846754 0.3294205 2.9095566 1.809709e-03
## mixedTRUE 0.54735955 0.4993175 1.0962154 1.364923e-01
## ENTRUE 1.05803433 0.3763199 2.8115292 2.465331e-03
## TCTRUE -0.13671777 0.5469141 -0.2499803 4.013013e-01
## T_constructionTRUE 0.34072092 0.3602944 0.9456736 1.721575e-01
## landfillTRUE 0.20089756 0.3217457 0.6243985 2.661829e-01
## leakTRUE 0.05852226 0.2374896 0.2464203 4.026785e-01
## garbageTRUE 0.07488315 0.2954338 0.2534685 3.999531e-01
## crackTRUE 1.80726206 0.3356268 5.3847369 3.627534e-08
## leaning_wallTRUE 2.01826928 0.5475272 3.6861534 1.138346e-04
## treeTRUE -0.05640807 0.2391328 -0.2358860 4.067606e-01
## tiltedTRUE 1.18959792 0.3343679 3.5577512 1.870217e-04
## angleD 0.84675859 0.4915621 1.7225874 4.248158e-02
## angleE 1.30374217 0.5444045 2.3948044 8.314617e-03
## ground_vegTRUE 1.08021836 0.2790457 3.8711158 5.416915e-05
## scarsTRUE 4.22468431 0.4011933 10.5302975 3.131809e-26
## conc_rainfallTRUE 2.73430638 0.7553445 3.6199459 1.473323e-04
## wastewaterTRUE 0.93190708 0.2403299 3.8776153 5.274266e-05
## bananaTRUE 0.21831583 0.2567834 0.8501945 1.976085e-01
## R1|R2 2.77094701 1.2624858 2.1948341 1.408775e-02
## R2|R3 7.07044977 1.3069745 5.4097839 3.155043e-08
## R3|R4 12.59307323 1.4371266 8.7626752 9.533520e-19
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.53 0.52 -1.02 0.15
## woodTRUE 0.96 0.33 2.91 0.002
## mixedTRUE 0.55 0.50 1.10 0.14
## ENTRUE 1.06 0.38 2.81 0.002
## TCTRUE -0.14 0.55 -0.25 0.40
## T_constructionTRUE 0.34 0.36 0.95 0.17
## landfillTRUE 0.20 0.32 0.62 0.27
## leakTRUE 0.06 0.24 0.25 0.40
## garbageTRUE 0.07 0.30 0.25 0.40
## crackTRUE 1.81 0.34 5.38 0.0000
## leaning_wallTRUE 2.02 0.55 3.69 0.0001
## treeTRUE -0.06 0.24 -0.24 0.41
## tiltedTRUE 1.19 0.33 3.56 0.0002
## angleD 0.85 0.49 1.72 0.04
## angleE 1.30 0.54 2.39 0.01
## ground_vegTRUE 1.08 0.28 3.87 0.0001
## scarsTRUE 4.22 0.40 10.53 0
## conc_rainfallTRUE 2.73 0.76 3.62 0.0001
## wastewaterTRUE 0.93 0.24 3.88 0.0001
## bananaTRUE 0.22 0.26 0.85 0.20
## R1| R2 2.77 1.26 2.19 0.01
## R2| R3 7.07 1.31 5.41 0.0000
## R3| R4 12.59 1.44 8.76 0
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+---------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+---------+------------+----------+
## |brick |No | 31|Inf | 3.401197| 1.232143681|-0.8938179|
## | |Yes|498|Inf | 2.285041|-0.072320662|-2.0069620|
## +--------------+---+---+----+---------+------------+----------+
## |wood |No |451|Inf | 2.199691|-0.164449432|-2.3025851|
## | |Yes| 78|Inf | 3.637586| 0.998528830|-0.6359888|
## +--------------+---+---+----+---------+------------+----------+
## |mixed |No |492|Inf | 2.271678|-0.089490571|-2.0126015|
## | |Yes| 37|Inf | 3.583519| 1.287854288|-0.9932518|
## +--------------+---+---+----+---------+------------+----------+
## |EN |No |346|Inf | 1.850296|-0.483174092|-2.4693542|
## | |Yes|183|Inf | Inf| 0.950976290|-1.2422550|
## +--------------+---+---+----+---------+------------+----------+
## |TC |No | 24|Inf | Inf| 1.098612289|-1.0986123|
## | |Yes|505|Inf | 2.276722|-0.051496526|-1.9664354|
## +--------------+---+---+----+---------+------------+----------+
## |T_construction|No |213|Inf | 1.559566|-0.890145452|-3.1208954|
## | |Yes|316|Inf | 3.421000| 0.572069249|-1.4715386|
## +--------------+---+---+----+---------+------------+----------+
## |landfill |No |330|Inf | 1.820333|-0.520534438|-2.6888188|
## | |Yes|199|Inf | 5.288267| 0.888316880|-1.1737329|
## +--------------+---+---+----+---------+------------+----------+
## |leak |No |343|Inf | 1.942582|-0.335472736|-2.4203681|
## | |Yes|186|Inf | 3.817712| 0.621403276|-1.2947272|
## +--------------+---+---+----+---------+------------+----------+
## |garbage |No |345|Inf | 2.089262|-0.250578322|-2.3154058|
## | |Yes|184|Inf | 2.967561| 0.464707942|-1.3795147|
## +--------------+---+---+----+---------+------------+----------+
## |crack |No |435|Inf | 2.134938|-0.386344067|-2.7972813|
## | |Yes| 94|Inf | 4.532599| 2.685577345|-0.1706255|
## +--------------+---+---+----+---------+------------+----------+
## |leaning_wall |No |497|Inf | 2.259100|-0.124910650|-2.1684933|
## | |Yes| 32|Inf | Inf| 3.433987204| 0.1251631|
## +--------------+---+---+----+---------+------------+----------+
## |tree |No |206|Inf | 1.693319|-0.536801110|-2.1758334|
## | |Yes|323|Inf | 3.022050| 0.331167184|-1.7702533|
## +--------------+---+---+----+---------+------------+----------+
## |tilted |No |436|Inf | 2.113432|-0.399734433|-2.5698999|
## | |Yes| 93|Inf | Inf| 3.102342009|-0.4144338|
## +--------------+---+---+----+---------+------------+----------+
## |angle |C | 32|Inf | Inf|-0.251314428|-3.4339872|
## | |D |119|Inf | 4.770685| 1.000172216|-1.2259517|
## | |E |378|Inf | 1.976494|-0.276887827|-2.1341664|
## +--------------+---+---+----+---------+------------+----------+
## |ground_veg |No |156|Inf | 1.203973|-1.519825754|-2.9177707|
## | |Yes|373|Inf | 3.493749| 0.543850879|-1.6518586|
## +--------------+---+---+----+---------+------------+----------+
## |scars |No |327|Inf | 1.784642|-1.337320357|-4.6821312|
## | |Yes|202|Inf | Inf| 3.486355190|-0.7455937|
## +--------------+---+---+----+---------+------------+----------+
## |conc_rainfall |No | 12|Inf |-1.098612|-2.397895273| -Inf|
## | |Yes|517|Inf | 2.534114| 0.034819765|-1.8875152|
## +--------------+---+---+----+---------+------------+----------+
## |wastewater |No |204|Inf | 1.574551|-0.417735201|-3.0757750|
## | |Yes|325|Inf | 3.261297| 0.253659095|-1.5059589|
## +--------------+---+---+----+---------+------------+----------+
## |banana |No |348|Inf | 1.932838|-0.383958903|-2.1908551|
## | |Yes|181|Inf | 4.083171| 0.751741345|-1.5007047|
## +--------------+---+---+----+---------+------------+----------+
## |Overall | |529|Inf | 2.327797|-0.003780723|-1.9138903|
## +--------------+---+---+----+---------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 5 12 2 0
## R2 8 75 10 0
## R3 0 14 59 11
## R4 0 1 18 9
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.3392857
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 6 11 2 0
## R2 8 74 11 0
## R3 0 13 60 11
## R4 0 0 17 11
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3258929
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 7 10 2 0
## R2 10 75 8 0
## R3 0 16 58 10
## R4 0 0 18 10
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.3303571
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 7 10 2 0
## R2 10 75 8 0
## R3 0 15 59 10
## R4 0 0 18 10
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.3258929
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 5 12 2 0
## R2 6 76 11 0
## R3 0 13 62 9
## R4 0 1 17 10
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.3169643
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 5 12 2 0
## R2 7 76 10 0
## R3 0 16 58 10
## R4 0 1 17 10
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.3348214
#Table
df2 <- data.frame(
"Equations"=c(1:6),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6
)
)
df2
## Equations Predicted
## 1 1 0.6607143
## 2 2 0.6741071
## 3 3 0.6696429
## 4 4 0.6741071
## 5 5 0.6830357
## 6 6 0.6651786